import 'package:enterprise_v6_app/app/components/dialog/exit_tips.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/modules/profile/controller.dart';

/// 流程审批底部按钮
/// [onOpinion] 输入回调
/// [onSign] 签字回调
/// [onOperation] 确认回调
/// [isShowNoPass] 是否显示不通过按钮
class ApprovalBottomSheet extends StatefulWidget {
  const ApprovalBottomSheet({super.key, this.onOpinion, this.onSign, this.onOperation, this.isShowNoPass});

  final Function(String opinion)? onOpinion;
  final Function(String signUrl)? onSign;
  final Function(int type)? onOperation;
  final bool? isShowNoPass;

  @override
  State<ApprovalBottomSheet> createState() => _ApprovalBottomSheetState();
}

class _ApprovalBottomSheetState extends State<ApprovalBottomSheet> {
  final profile = Get.find<HomeMyController>();

  @override
  void initState() {
    super.initState();
    if (widget.onSign != null) {
      widget.onSign!(profile.entity?.signatureUrl ?? '');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 220.w,
      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.w),
      decoration: BoxDecoration(
        color: Colors.white,
        boxShadow: [
          BoxShadow(
            color: const Color(0xffBCBCC5).withOpacity(0.3), // 阴影颜色
            offset: const Offset(0, -5), // 阴影的偏移量，向上偏移，即上方阴影
            blurRadius: 10.0, // 阴影的模糊半径
            spreadRadius: 2.0, // 阴影的扩散半径
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            '审批意见',
            style: TextStyle(
              fontSize: 16.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xff495061),
            ),
          ),
          AppGaps.vGap8,
          Container(
              height: 65.w,
              decoration: BoxDecoration(
                color: const Color(0xffF7F7FB),
                borderRadius: BorderRadius.all(Radius.circular(8.w)),
                border: Border.all(width: 1.w, color: const Color(0xffEBEDF0)),
              ),
              child: TextField(
                  keyboardType: TextInputType.text,
                  textInputAction: TextInputAction.done,
                  maxLines: null,
                  maxLength: 250,
                  onChanged: (value) {
                    if (widget.onOpinion != null) {
                      widget.onOpinion!(value.toString());
                    }
                  },
                  style: TextStyle(color: const Color(0xFF262F38), fontWeight: FontWeight.w400, fontSize: 14.w),
                  decoration: InputDecoration(
                    counterText: '',
                    //防止适配不居中
                    isCollapsed: true,
                    border: const OutlineInputBorder(borderSide: BorderSide.none),
                    contentPadding: EdgeInsets.symmetric(vertical: 5.w, horizontal: 9.w),
                    hintText: '请输入审批意见',
                    hintStyle: TextStyle(fontSize: 14.w, fontWeight: FontWeight.w400, color: const Color(0xffA0A7B5)),
                  ))),
          Container(
            padding: EdgeInsets.only(top: 16.w),
            child: Divider(height: 1.w, color: const Color(0xFFECEEF3)),
          ),
          Expanded(
            child: Row(
              children: [
                Text(
                  '*',
                  style: TextStyle(
                    fontSize: 14.sp,
                    height: 1.2,
                    color: AppColors.meaning_color_danger,
                  ),
                ),
                Text(
                  '审批人',
                  style: TextStyle(
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w500,
                    color: const Color(0xff495061),
                  ),
                ),
                const Spacer(),
                Container(
                  margin: EdgeInsets.only(top: 8.w, right: 8.w),
                  width: 76.w,
                  height: 36.w,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(4.w),
                      color: Colors.white,
                      border: Border.all(
                        color: const Color(0xFFEFF2F6),
                        width: 1,
                      ),
                      image: DecorationImage(
                        image: NetworkImage(Interface.fileUrl + profile.entity!.signatureUrl),
                      )),
                ).clickShowLarge(url: Interface.fileUrl + profile.entity!.signatureUrl)
              ],
            ),
          ),
          AppGaps.vGap6,
          Row(
            children: [
              Container(
                  height: 40.w,
                  width: 90.w,
                  margin: EdgeInsets.only(right: 10.w),
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: const Color(0xffffffff),
                      border: Border.all(color: const Color(0xffFD6B6B), width: 1.w),
                      borderRadius: BorderRadius.all(Radius.circular(20.w))),
                  child: Text(
                    '驳回',
                    style: TextStyle(
                      fontSize: 16.sp,
                      color: const Color(0xffFD6B6B),
                    ),
                  )).clickOnce(() {
                // 弹窗提示
                Get.dialog<bool>(ExitTips(
                  content: '确认驳回？',
                  func: (b) {
                    if (b) {
                      if (widget.onOperation != null) {
                        widget.onOperation!(2);
                      }
                    }
                  },
                ));
              }),
              Visibility(
                visible: widget.isShowNoPass ?? false,
                child: Container(
                    height: 40.w,
                    width: 90.w,
                    margin: EdgeInsets.only(right: 10.w),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: const Color(0xffffffff),
                        border: Border.all(color: const Color(0xffFD6B6B), width: 1.w),
                        borderRadius: BorderRadius.all(Radius.circular(20.w))),
                    child: Text(
                      '不通过',
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: const Color(0xffFD6B6B),
                      ),
                    )).clickOnce(() {
                  // 弹窗提示
                  Get.dialog<bool>(ExitTips(
                    content: '确认不通过？',
                    func: (b) {
                      if (b) {
                        if (widget.onOperation != null) {
                          widget.onOperation!(3);
                        }
                      }
                    },
                  ));
                }),
              ),
              Expanded(
                child: Container(
                    height: 40.w,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(color: const Color(0xff5C6DFF), borderRadius: BorderRadius.all(Radius.circular(20.w))),
                    child: Text(
                      '通过',
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: const Color(0xffffffff),
                      ),
                    )).clickOnce(() {
                  if (widget.onOperation != null) {
                    widget.onOperation!(1);
                  }
                }),
              ),
            ],
          )
        ],
      ),
    );
  }
}
